package org.maitaole.service.impl;

import org.maitaole.entity.TbCartDetail;
import org.maitaole.mapper.TbCartDetailMapper;
import org.maitaole.service.ITbCartDetailService;
import org.maitaole.service.ITbCartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TbCartDetailServiceImpl implements ITbCartDetailService {

    @Resource
    private TbCartDetailMapper tbCartDetailMapper;

    @Resource
    private ITbCartService iTbCartService;

    @Override
    public int insertTbCartDetails(String infoDetailIdStr) {
        String[] split = infoDetailIdStr.substring(infoDetailIdStr.indexOf("[")+1, infoDetailIdStr.lastIndexOf("]")).split(",");
        Integer[] splitInt = new Integer[split.length];
        for (int i = 0; i < split.length; i++) {
            System.out.println(split[i]);
            splitInt[i] = Integer.parseInt(split[i]);
            System.out.println("splitInt[i] = " + (splitInt[i]+1));
        }
        int tbCartLastPrimaryKey = iTbCartService.selectLastPrimaryKey();
        int number = 0;
        for (int i = 0; i < split.length; i++) {
            TbCartDetail tbCartDetail = new TbCartDetail(null, tbCartLastPrimaryKey, splitInt[i]);
            System.out.println(tbCartLastPrimaryKey);
            int i1 = tbCartDetailMapper.insertSelective(tbCartDetail);
            number += i1;
        }
        return number;
    }
}
